<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/manage/commons/taglibs.jsp"%>
<link rel="stylesheet" type="text/css" href="/resources/ace/css/cacheCloud-appCommand.css"/>
<style>
    .navbar-nav li a:hover {
        text-decoration: underline;
    }
</style>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
    <div class="container">
        <!-- <div class=""> -->
            <ul class="nav navbar-nav navbar-left">
                <li>
                    <a href="/admin/app/list"><font color='white'>首页</font></a>
                </li>
            </ul>
            <!-- <a class="navbar-brand" href="/admin/app/list">首页</a> -->
        <!-- </div> -->
        <div class="navbar-collapse collapse">
            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span class="glyphicon glyphicon-cog"></span>
                        <font color='white'> ${userInfo.chName}</font>
                        <b class="caret"></b>
					</a>
					<ul class="dropdown-menu">
						<c:if test="${userInfo.type == 0}">
							<li><a target="_self" href="/manage/total/statlist"><span class="glyphicon glyphicon-th-large"></span> 管理后台</a></li>
                            <li class="divider"></li>
						</c:if>
						<li><a href="/admin/app/list"><span class="glyphicon glyphicon-th-list"></span> 应用列表</a></li>
                        <c:if test="${userInfo.type != 2}">
                            <li><a target="_self" href="/admin/app/jobs"><span class="glyphicon glyphicon-list-alt"></span> 我的申请</a></li>
                        </c:if>
    					<c:if test="${userInfo.type ne 0}">
        					<li><a id="updatePwdBtn" href="javascript;"><span class="glyphicon glyphicon-lock"></span> 修改密码</a></li>
                        </c:if>
						<li><a href="/manage/logout"><span class="glyphicon glyphicon-log-out"></span> 注销</a></li>
					</ul>
                </li>
            </ul>
            
            <ul class="nav navbar-nav navbar-left">
                <li>
                    <a href="/wiki/quickstart/index"><font color='white'>帮助文档</font>
					</a>
                </li>
            </ul>
            
            <div class="editDialog" id="updatePwdDialog" style="z-index: 10">
                <div class="editDialog-con" style="width: 30%">
                    <div class="editDialog-con-title">
                        <span>修改密码</span>
                    </div>
                    <div class="editDialog-con-form">
                        <div class="form-item" id="dialogInput">
                            <p>密码:</p>
                            <input type="password" class="cacheCloud-input">
        					<p class="help-block">密码中必须包含字母、数字，至少8个字符</p>
                        </div>
                    </div>
                    <div class="editDialog-con-btns">
                        <div></div>
                        <div>
                            <button class="btn btn-default" id="closeDialog">取消</button>
        					<button class="btn btn-info" id="saveDialog" data-id="${userInfo.id}">保存</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function() {
        var pwdRegex = new RegExp('(?=.*[0-9])(?=.*[a-zA-Z]).{8,30}');
        $("#updatePwdBtn").click(function(e) {
            e.preventDefault();
            $("#updatePwdDialog").css("display", "flex");
        })
        $("#closeDialog").click(function() {
            $("#updatePwdDialog").css("display", "none");
        });
        $("#saveDialog").click(function() {
			var pwd = $("#dialogInput input").val();
			if(!pwdRegex.test(pwd)) {
                alert("您的密码复杂度太低，密码中必须包含字母、数字、特殊字符至少8个字符，请修改密码！");
				return;
			}
			$.ajax({
                url: "/user/updatePwd",
				type: "post",
				dataType: "json",
				xhrFields: {
					withCredentials: true
				},
				data: {
					userId: $(this).data("id"),
					password: pwd
				},
				success: function(res) {
					if(res.status) {
                        alert("修改成功");
                        $("#dialogInput input").val("");
                        $("#updatePwdDialog").css("display", "none");
                    }
					else alert("修改失败");
				}
			});
        });
    })
</script>
